package com.thread;

/**
 * JoinTest--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-08-21 17:33
 **/
public class JoinTest extends Thread {

    public JoinTest(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(getName() + "" + i);
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            if (i == 5) {
                JoinTest tempJoin = new JoinTest("半路线程");
                tempJoin.start();
                try {
                    /* 这里5000代表主线程等待tempJoin线程超时时间为5秒，
                    也就是说不管tempJoin在5秒后执行完没有都会继续执行主线程 */
                    tempJoin.join(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName()+":"+i);
        }
    }
}